﻿using System.ComponentModel;
using System.Windows.Media;
using MyFloridaHouse.libSvCommonUtilities;
using MyFloridaHouse.libSvOpenDistricts.Districts;
using MyFloridaHouse.libSvOpenDistricts.MapShapes;
using MyFloridaHouse.ServiceConn.DistrBldrSvcRef;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using MyFloridaHouse.libSvOpenDistricts.SummaryDataGrid;
using System;


namespace MyFloridaHouse.libSvOpenDistricts.ViewModel
{
    public partial class ViewModelBase
    {
        private DistrictPlan _districtPlan;
        public DistrictPlan districtPlan
        {
            get { return _districtPlan; }
            set
            {
                if (_districtPlan != value)
                {
                    _districtPlan = value;

                    NotifyPropertyChanged("districtPlan");
                }
            }
        }



        private MapShapeLayer _districtMapLayer;
        public MapShapeLayer districtMapLayer
        {
            get { return _districtMapLayer; }
            set { if (_districtMapLayer != value) { _districtMapLayer = value; } }
        }

        #region methods



        private void createDistrictMapLayer()
        {
            // need to simulate a response from the service with information from the AppLayers table
            LayerDTO districtLayer = new LayerDTO();
            districtLayer.layerid = -1;
            districtLayer.layername = Constants.DistrictLayerName;
            districtLayer.defaultstrokecolor = "BLUE";
            districtLayer.defaultfillcolor = "ORANGE";
            districtLayer.zoommin = 1;
            districtLayer.zoommax = 21;

            //TODO: Delete these when removed from appLayer
            districtLayer.isStoreInMemory = false;
            districtLayer.isGraphLayer = false;
            districtLayer.isFindLayer = false;

            // create a new layer and add it to the map
            districtMapLayer = new MapShapeLayer(serviceDAL, myXamlMainMap, districtLayer, MapShapeLayer.enuMLayerAddLocation.bottom, true, districtLabel, districtFill);
            districtMapLayer.SetRegionDetails(1.0, new SolidColorBrush(Colors.Blue), 1.0, new SolidColorBrush(Colors.Blue));
            districtMapLayer.showFill = true;
            districtMapLayer.predefinedRegions = false;
            districtMapLayer.showLayer = true;
            districtMapLayer.showRegionNames = true;

            districtMapLayer.PropertyChanged += OnDistrictMapLayerPropertyChanged;
        }

        private void OnDistrictMapLayerPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            // whenever show layer is changed, activate the district layer to turn on or off
            if (e.PropertyName == "showLayer")
            {
                if (districtMapLayer.showLayer)
                {
                    districtPlan.GetDistrictsInView();
                }
            }
        }

        private void OnDistrictLabelDataChanged(object sender, EventArgs args)
        {
            districtMapLayer.ReplaceLabels();
        }

        private void OnDistrictFillConditionsChanged(object sender, EventArgs args)
        {
            districtMapLayer.ReplaceFillColor();
        }
        #endregion

    }
}
